package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * problem数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
     * sql查询
     * @param labelid
     * @param of
     * @return
     */
    @Query(value="SELECT * FROM tb_problem t1 LEFT JOIN tb_pl t2 ON t1.id = t2.problemid WHERE t2.labelid = ?1 order by t1.replytime desc",nativeQuery = true)
    Page<Problem> newlist(String labelid, Pageable of);

    @Query(value="SELECT * FROM tb_problem LEFT JOIN tb_pl  ON id = problemid WHERE labelid = ?1 and reply > 0 ORDER BY reply DESC",nativeQuery = true)
    Page<Problem> hotlist(String labelid,  Pageable of);

    @Query(value="SELECT * FROM tb_problem LEFT JOIN tb_pl  ON id = problemid WHERE labelid = ?1 AND reply=0",nativeQuery = true)
    Page<Problem> waitlist(String labelid, Pageable of);


}
